package com.daiziru.config;

import com.daiziru.template.HotsTemplate;
import com.daiziru.template.PostsTemplate;
import com.daiziru.template.TimeAgoMethod;
import com.jagregory.shiro.freemarker.ShiroTags;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

@Configuration
public class FreemarkerConfig {

    @Autowired
    private freemarker.template.Configuration configuration;

    @Autowired
    private PostsTemplate postsTemplate;
    @Autowired
    HotsTemplate hotsTemplate;



    @PostConstruct
    public void setUp() {
        //时间转换自定义配置
        configuration.setSharedVariable("timeAgo", new TimeAgoMethod());
        //置顶贴子自定义标签配置
        configuration.setSharedVariable("posts",postsTemplate);
        //本周热议
        configuration.setSharedVariable("hots",hotsTemplate);
        //shiro的Freemarker标签
        configuration.setSharedVariable("shiro", new ShiroTags());

    }

}
